<!--
    
    Author: Alex
    Date: 2021/9/25
-->
<div th:fragment="top">
    <div>
        <h1 id="userId"></h1>
    </div>
</div>


<div th:fragment="topscript">
    <script>
        verify();
        function verify() {
            var userId = localStorage.userId;
            if (userId == undefined || userId == '' || userId == null) {
                layer.prompt({title: '请输入您的姓名:', formType: 0}, function (val, index) {
                    $.get("/userIdListIsServer?user=" + val, function (result) {
                        if (result == false) {
                            $.get("/addOnLineUser?userId=" + val, function (res) {
                                layer.close(index);
                                localStorage.userId = val;
                                $("#userId").text(localStorage.userId);
                            });
                        }else{
                            layer.msg("名字已重复");
                        }
                    });
                });
            }else{
                $.get("/addOnLineUser?userId=" + localStorage.userId, function (res) {
                    $("#userId").text(localStorage.userId);
                });
                return true;
            }
        }
    </script>
</div>